<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>教练管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../static/css/style.css" media="all">
    <script type="text/javascript" src="../../static/js/jquery.min.js"></script>
    <script type="text/javascript" src="../../layui/layui.all.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/js/jquery.cookie.js"></script>
    <script type="text/javascript" src="../../static/js/base.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../static/js/ax.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
    <script src="../../static/js/html5.js"></script>
    <script src="../../static/js/respond.js"></script>
    <![endif]-->
</head>
<body class="bg_w">

<div class="layui-fluid">
    <div class="content-wrap">
       <!-- <div class="layui-row layui-col-space15">
            <div class="layui-col-sm4">
                <label class="layui-form-label">岗位代码</label>
                <div class="layui-input-block">
                    <input type="text" name="code" id="code" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-col-sm4">
                <label class="layui-form-label">岗位名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" id="name" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-col-xs4">
                <button class="layui-btn add_btn" data-type="reload" onclick="searchBtn()" ><i class="layui-icon layui-icon-search"></i>搜索</button>
            </div>
        </div>-->
        <div class="layui-row">
            <input type="hidden" name="carId" id="carId">
            <table class="layui-hide" id="coach" lay-filter="eventBtn"></table>
            <script type="text/html" id="barDemo">
                <div class="layui-input-block">
                    <input type="checkbox" checked="" name="open" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">
                </div>
            </script>
        </div>
    </div>
</div>

<script>


    var tableIns;
    var carId;
    $(document).ready(function(){
        carId= getQueryString('carId');
        $("#carId").val(carId);

        layui.use(['table', 'layer','element','form'], function(){
            //监听指定开关
            var form = layui.form;
            form.on('switch(switchTest)', function(data){
                var coachId=data.value;
                var url=this.checked ? schoolWebUrl+"/api/coachCar/addCoachCar" : schoolWebUrl+"/api/coachCar/delCoachCar"
                ax.post({
                    url: url,
                    type: "POST",
                    data:{"coachId":coachId,"carId":carId},
                    contentType: "application/x-www-form-urlencoded",
                    success: function(data){
                        if(data.code==0){
                            layer.msg(data.message, {icon: 6});
                        }else{
                            layer.msg(data.message, {icon: 5});
                        }
                    }
                });
            });

            var table = layui.table;
            tableIns =ax.VTable({
                elem: "#coach",
                url:schoolWebUrl+"/api/coachCar/list?carId="+carId,
                method: 'POST',
                cols: [[
                    {field:'序列号', width:80, title: '序列号', sort: true,type:'numbers'},
                    {field:'coachName', title: '教练姓名'},
                    {field:'idnum', title: '身份证'},
                   // {field:'id', title: 'cc'},
                    {field:'left', title: '是否分配',width: 100,templet:function(d){
                        if(d.id==null || d.id==""){
                            return '<div> <input type="checkbox" value="'+d.coachId+'"   name="open" lay-skin="switch" lay-filter="switchTest" lay-text="开启|关闭"> </div>';
                        }else{
                            return '<div> <input type="checkbox" value="'+d.coachId+'" checked name="close" lay-skin="switch" lay-filter="switchTest" lay-text="开启|关闭"> </div>';
                        }
                     }}
                    /*{field:'right', title: '操作',width: 270,toolbar:"#barDemo"}*/
                ]]
            });

            //监听行单击事件（单击事件为：rowDouble）
            table.on('row(eventBtn)', function(obj){
                var postionJson = obj.data;
                //标注选中样式
                obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
            });

        });
    });
    //搜索
    function searchBtn(){
        tableIns.reload({
            where: {
                name:$("#name").val(),
                code:$("#code").val(),
                depCode:departmentCode
            }
        });
    };
</script>
</body>
</html>